﻿using RedisUtil;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace 生产者
{
    class Program
    {
        static void Main(string[] args)
        {
            ThreadPool.SetMaxThreads(20, 20);
            ThreadPool.SetMinThreads(10, 10);

            BaseRedis redis = new BaseRedis();

            var computerId = Guid.NewGuid().ToString("N");

            var queueKey = "queue";

            var flag = 0;

            // 多线程向 Redis 队列添加任务
            for (int i = 0; i < 5; i++)
            {
                Task.Run(() =>
                {
                    while (true)
                    {
                        // 添加任务
                        redis.DB.ListLeftPush(queueKey, $"{computerId} - {flag++}");
                        Thread.Sleep(200); // 每秒钟5个请求
                    }
                });
            }

            Console.ReadKey();
        }
    }
}
